package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.display.BitmapData;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	import flash.utils.ByteArray;
	import flash.utils.getQualifiedClassName;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.graphics.*;
	import org.aswing.tree.AbstractLayoutCache;
	
		
	public class PanelProgress extends JPanel
	{
		
		//members define
		//private var panelValue:JPanel;
		
		//members define
		private var labelValue:JLabel;
		
		public function PanelProgress()
		{
			//component creation
			setLocation(new IntPoint(0, 0));
			setSize(new IntDimension(70, 15));
			setPreferredSize(new IntDimension(70, 15));
			var layout0:EmptyLayout = new EmptyLayout();
			setLayout(layout0);
			
			labelValue = new JLabel();
			labelValue.setLocation(new IntPoint(0, 0));
			labelValue.setSize(new IntDimension(70, 15));
			labelValue.setPreferredSize(new IntDimension(70, 15));
			labelValue.setText("label");
			labelValue.setSelectable(false);
			labelValue.setHorizontalAlignment(AsWingConstants.CENTER);
			labelValue.setVerticalAlignment(AsWingConstants.CENTER);
			labelValue.setHorizontalTextPosition(AsWingConstants.CENTER);
			labelValue.setVerticalTextPosition(AsWingConstants.CENTER);
			
			//component layoution
			append(labelValue);
			
			
			//_strValueResource = strResource;
			setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_p_bg") as DisplayObject));
			//setResource(strResource);
			
			var filter:GlowFilter;
			filter = new GlowFilter(0x000000, 1, 2, 2, 100);
			labelValue.setForeground(new ASColor(0xFFFFFF, 1));
			labelValue.setFont(new ASFont("宋体", 11, false, false, false, false));
			labelValue.setTextFilters(new Array(filter));
			
			bringToTop(labelValue);
			labelValue.setVisible(false);
			this.pack();
			this.paintImmediately();
		}
		public function setResource(strResource:String):void
		{
			_mcValue = Client.getUIElement(strResource) as MovieClip;
			if(_bmValue == null)
			{
				var data:BitmapData = new BitmapData(this.width,this.height,true,0x000000);
				_bmValue = new Bitmap(data);
				addChild(_bmValue);
				_bmValue.x = 0;
				_bmValue.y = 0;
			}
			_bmDataValueRaw = new BitmapData(_mcValue.width,_mcValue.height,true,0x000000);
			_bmDataValueRaw.draw(_mcValue);
		}
		//private var _strValueResource:String = null;
		private var _mcValue:MovieClip = null;
		//private var _panelValue:JPanel = new JPanel;
		private var _maximum:int = 0;
		private var _value:int = 0;
		private var _bmValue:Bitmap = null;
		private var _bmDataValueRaw:BitmapData = null;
		public function setMaxValue(maximum:int):void
		{
			_maximum = maximum;
			labelValue.setText(_value+'/'+_maximum);
			update();
		}
		public function setValue(value:int):void
		{
			_value = value;
			labelValue.setText(_value+'/'+_maximum);
			update();
		}
		public function updateValue(value:int,maxValue:int):void
		{
			_maximum = maxValue;
			_value = value;
			labelValue.setText(_value+'/'+_maximum);
			update();
			this.bringToTop(labelValue);
		}

		public function setTextVisible(visible:Boolean):void
		{
			labelValue.setVisible(visible);
			this.pack();
			this.paintImmediately();
		}
		public function update():void
		{
			var per:uint = Math.floor(_value *100 / _maximum);
			if (per > 100) 
				per = 100;
			var rect:Rectangle = new Rectangle(0,0,_mcValue.width * per /100,_mcValue.height);
			

			//_bmValue.bitmapData.copyPixels(_bmDataValueRaw,new Rectangle(0,0,_mcValue.width,_mcValue.height),new Point(0,0),null,null,true);
			_bmValue.bitmapData.dispose();
			_bmValue.bitmapData = new BitmapData(this.width,this.height,true,0x000000)
			
			_bmValue.bitmapData.copyPixels(_bmDataValueRaw,rect,new Point(0,0),null,null,true);

			this.pack();
			this.paintImmediately();
		}
	}
}